﻿using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Runtime;
using Android.Support.Design.Widget;
using Android.Support.V7.App;
using Android.Support.V7.Widget;
using Android.Util;
using Android.Views;
using Com.Tencent.Android.Tpush;
using System;

namespace Xamarin.TPNS.Demo
{
    [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
    public class MainActivity : AppCompatActivity, IXGIOperateCallback
    {
        private const string TAG = "MainActivity";

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
            fab.Click += FabOnClick;
        }

        public override bool OnCreateOptionsMenu(IMenu menu)
        {
            MenuInflater.Inflate(Resource.Menu.menu_main, menu);
            return true;
        }

        public override bool OnOptionsItemSelected(IMenuItem item)
        {
            int id = item.ItemId;
            if (id == Resource.Id.action_settings)
            {
                return true;
            }

            return base.OnOptionsItemSelected(item);
        }

        private void FabOnClick(object sender, EventArgs eventArgs)
        {
            View view = (View)sender;
            Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong)
                .SetAction("Action", (View.IOnClickListener)null).Show();

            XGPushConfig.EnableDebug(this, true);

            //开启第三方通道
            XGPushConfig.EnableOtherPush(this, true);
            //		//小米通道
            //		XGPushConfig.setMiPushAppId(this, "2882303761517672364");
            //		XGPushConfig.setMiPushAppKey(this, "5271767210364");
            //魅族通道
            XGPushConfig.SetMzPushAppId(this, "111888");
            XGPushConfig.SetMzPushAppKey(this, "484a31262cf24dc9b568b5445d9e0495");
            XGPushConfig.SetOppoPushAppId(this, "");
            XGPushConfig.SetOppoPushAppKey(this, "");

            // 注册接口
            XGPushManager.RegisterPush(ApplicationContext, this);
        }

        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults)
        {
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }

        public void OnFail(Java.Lang.Object p0, int p1, string p2)
        {
            Log.Info(TAG, "OnFail--> p0->" + p0 + "-" + "p1->" + p1 + " p2->" + p2);
        }

        public void OnSuccess(Java.Lang.Object p0, int p1)
        {
            Log.Info(TAG, "OnSuccess--> p0->" + p0 + "-" + "p1->" + p1);
        }
    }
}
